<template>
	<view>
		<view class="input">
			<input type="text" placeholder="请输入兑换码" @change="getNickname" @confirm='confirminput'
				v-model="inputClearValue" />
			<uni-icons @click="clearinputvalue" v-if="showClearIcon" type="clear" size="20" color="#E5E5E5"></uni-icons>
		</view>
		<view class="footerbtn">
			<view class="cont" @click="handleDuihc">
				<view class="btn" :class="showClearIcon?'':'absbtn'">
					兑换
				</view>
			</view>
		</view>

		<uni-popup ref="popup" type="center">
			<view class="popup">
				<view class="imgbcg">
					<image class="img" src="../static/ljuan5.png" mode=""></image>
					<view class="abs">
						<image src="../static/ljuan6.png" mode=""></image>
						<view class="t1">
							{{info.amount.integer}}
							<text v-if="info.amount.decimal">.{{info.amount.decimal}}</text>
						</view>
						<view class="t2">
							满 {{info.require}} 可用
						</view>
						<view class="ts">
							<view class="we">
								优惠多多~快去使用吧~
							</view>
							<view class="t"></view>
						</view>
						<view class="btn" @click="pageconsumer">
							立即查看
						</view>
					</view>
				</view>
				<view class="close" @click="close">
					<uni-icons size="40" color="#fff" type="close"></uni-icons>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		couponReplace
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				inputClearValue: '',
				showClearIcon: false,

				info: {}
			};
		},
		watch: {
			inputClearValue(oldval, newval) {
				if (this.inputClearValue != '') {
					this.showClearIcon = true;
				} else {
					this.showClearIcon = false;
				}
			}
		},
		methods: {
			close() {
				this.$refs.popup.close()
			},
			pageconsumer() {
				uni.navigateBack()
			},
			handleDuihc() {
				if (this.showClearIcon) {
					couponReplace({
						replaceCode: this.inputClearValue
					}).then(res => {
						if (res.code == 200) {
						    this.inputClearValue = ''
							this.showClearIcon = false
							this.info = res.data
							this.info.amount = this.$splitNumber(this.info.amount)
							this.$refs.popup.open()
						}
					})
				}
			},
			confirminput(e) {
				this.inputClearValue = e.detail.value
			},
			clearinputvalue() {
				this.inputClearValue = ''
				this.showClearIcon = false;
			},
			getNickname(e) {
				console.log(e.detail.value);
			}
		}
	}
</script>

<style lang="scss">
	.input {
		width: 670rpx;
		height: 100rpx;
		background: #FBFBFB;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 20rpx auto;
		display: flex;
		align-items: center;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #000000;
		padding: 0rpx 20rpx;
		box-sizing: border-box;

		input {
			flex: 1;
		}
	}

	.footerbtn {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;

		.cont {
			display: flex;
			padding: 10rpx 20rpx;
			height: 120rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			align-items: center;
			justify-content: center;

			.btn {
				width: 670rpx;
				height: 100rpx;
				background: #000000;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				color: #FFFFFF;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 100rpx;
				text-align: center;
			}

			.absbtn {
				background: #808080;
			}
		}
	}



	.popup {
		.close {
			margin-top: 6rpx;
			text-align: center;
		}

		.imgbcg {
			width: 630rpx;
			height: 560rpx;
			position: relative;

			.img {
				width: 630rpx;
				height: 560rpx;
			}

			.abs {
				position: absolute;
				width: 630rpx;
				height: 560rpx;
				top: 0%;
				padding: 84rpx 94rpx 54rpx 94rpx;
				box-sizing: border-box;
				text-align: center;

				image {
					width: 284rpx;
					height: 84rpx;
					margin-left: 40rpx;
				}

				.t1 {
					font-family: 'DINB';
					font-weight: bold;
					font-size: 72rpx;
					line-height: 70rpx;

					text {
						font-size: 40rpx;
					}
				}

				.t2 {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #000000;
					margin-top: 6rpx;
				}

				.ts {
					width: 380rpx;
					height: 40rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #000000;
					margin: 10rpx auto;
					position: relative;

					.we {
						position: absolute;
						z-index: 9;
						font-size: 28rpx;
						left: 50rpx;
					}

					.t {
						width: 380rpx;
						height: 12rpx;
						background: #38CDA5;
						border-radius: 6rpx 6rpx 6rpx 6rpx;
						position: absolute;
						bottom: 0rpx;
					}
				}

				.btn {
					margin-top: 74rpx;
					width: 442rpx;
					height: 92rpx;
					background: #000000;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 32rpx;
					color: #FFFFFF;
					line-height: 92rpx;
				}

			}
		}
	}
</style>